package qimao.com.edu.service.impl;

import java.util.List;


import qimao.com.edu.DTO.BookDTO;
import qimao.com.edu.DTO.WorkQueryDTO;
import qimao.com.edu.VO.BookVO;
import qimao.com.edu.dao.BookDao;
import qimao.com.edu.dao.impl.BookDaoImpl;
import qimao.com.edu.entity.Page;
import qimao.com.edu.entity.Works;
import qimao.com.edu.service.WorksService;

public class WorksServiceImpl implements WorksService {
	
	private BookDao bookDao = new BookDaoImpl();
	@Override
	public Page<BookDTO> searchWorks(String str,int pageNum,int pageSize) {
		List<BookDTO> data = bookDao.selectBook(str, pageNum, pageSize);
		int totalRows = bookDao.selectBookTotalRows(str, pageNum, pageSize);
		Page<BookDTO> page = new Page(data, pageNum, pageSize,totalRows);
		return page;
	}
	
	@Override
	public Page<BookDTO> searchWorks(WorkQueryDTO workQueryDTO,Integer pageNum,Integer pageSize) {
		List<BookDTO> data = bookDao.selectWorksByConditions(workQueryDTO);
		int totalRows = bookDao.selectWorksByConditionsTotalRows(workQueryDTO);
		Page<BookDTO> page = new Page(data, pageNum, pageSize,totalRows);
		return page;
	}

	@Override
	public Works selectWorks(Integer workId) {
		return bookDao.selectWorks(workId);
	}
	
	@Override
	public BookDTO selectBookDTO(Integer workId) {
		return bookDao.selectBookDTO(workId);
	}

	@Override
	public Page<BookVO> searchAll(Integer pageNum, Integer pageSize) {
		List<BookVO> data = bookDao.searchAll(pageNum, pageSize);
		int totalRows = bookDao.searchAllTotalRows();
		Page<BookVO> page = new Page<BookVO>(data, pageNum, pageSize, totalRows);
		return page;
	}

	@Override
	public int createWork(Works work) {
		return bookDao.insertBook(work);
	}

	@Override
	public int deleteBook(int workId) {
		return bookDao.deleteWork(workId);
	}

}
